package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.bean.pagebean.ClassRoomPrombleBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/9/19
 * 问答列表
 */

public class ClassRoomPrombleAdapter extends BaseAdapter {


    private List<ClassRoomPrombleBean.PrombleListBean> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    ClassRoomPrombleBean.PrombleListBean bean;

    public ClassRoomPrombleAdapter(Context context, List<ClassRoomPrombleBean.PrombleListBean> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<ClassRoomPrombleBean.PrombleListBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_classrompromble, null);
            holder = new ViewHolder();
            holder.promble_text = (TextView) convertView.findViewById(R.id.promble_text);
            holder.reply_text = (TextView) convertView.findViewById(R.id.reply_text);
            holder.reply_nametext = (TextView) convertView.findViewById(R.id.reply_nametext);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (list.size() > 0) {
            bean = list.get(position);
            if (bean != null) {
                if (bean.getRemarks() != null) {//提问的问题
                    String content = bean.getRemarks();
                    holder.promble_text.setText(content);
                }
                if (bean.getQuestionAnswerList() != null) {//答案
                    if (bean.getQuestionAnswerList().size() > 0) {
                        if (bean.getQuestionAnswerList().get(0).getRemarks() != null) {
                            holder.reply_text.setText(bean.getQuestionAnswerList().get(0).getRemarks());
                        }
                        if (bean.getQuestionAnswerList().get(0).getCreateBy() != null) {
                            if (bean.getQuestionAnswerList().get(0).getCreateBy().getName() != null) {
                                holder.reply_nametext.setText(bean.getQuestionAnswerList().get(0).getCreateBy().getName());
                            }
                        }
                    } else {
                        holder.reply_text.setText("暂无");
                        holder.reply_nametext.setText("暂无");
                    }
                } else {
                    holder.reply_text.setText("暂无");
                    holder.reply_nametext.setText("暂无");
                }
            }
        }

        return convertView;
    }

    class ViewHolder {
        TextView promble_text;//问
        TextView reply_text;//答
        TextView reply_nametext;
    }

}
